package com.groupfifteen.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.groupfifteen.common.R;
import com.groupfifteen.entity.SysMultiQuestionEntity;
import com.groupfifteen.entity.SysUserEntity;
import com.groupfifteen.service.SysMultiQuestionService;
import com.groupfifteen.util.ApiResultHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("sysmultiquestion")
public class SysMultiQuestionController {

    @Autowired
    private SysMultiQuestionService sysMultiQuestionService;

    @PostMapping("/query")
    public IPage<SysMultiQuestionEntity> querySysMultiQuestions(@RequestBody SysMultiQuestionEntity sysMultiQuestionEntity,
                                                                @RequestParam(defaultValue = "1") int pageNo,
                                                                @RequestParam(defaultValue = "10") int pageSize) {
        return sysMultiQuestionService.QuerySysMultiQuestions(sysMultiQuestionEntity, pageNo, pageSize);
    }
    @PostMapping("addmultiquestion")
    public String AddMultiQuestion(@RequestBody SysMultiQuestionEntity sysMultiQuestionEntity) {
        Integer result = sysMultiQuestionService.AddMultiQuestion(sysMultiQuestionEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    //
    @DeleteMapping("/deletemultiquestion/{question_id}")
    public String DeleteMultiQuestion(@PathVariable("question_id") Integer question_id) {
        Integer result = sysMultiQuestionService.DeleteMultiQuestion(question_id);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
//hhiu
    @GetMapping("/getmultiquestion/{question_id}")
    public SysMultiQuestionEntity GetMultiQuestion(@PathVariable("question_id") Integer question_id) {
        SysMultiQuestionEntity result = sysMultiQuestionService.GetMultiQuestion(question_id);
        if (result != null) {
            return result;
        } else {
            return null;
        }
    }

    @PutMapping("/updatemultiquestion/{question_id}")
    public String UpdateMultiQuestion(@PathVariable("question_id")Integer question_id,@RequestBody SysMultiQuestionEntity sysMultiQuestionEntity) {
        sysMultiQuestionEntity.setQuestionId(question_id);
        Integer result = sysMultiQuestionService.UpdateMultiQuestion(sysMultiQuestionEntity);
        if (result > 0) {
            return "success";
        } else {
            return "fail";
        }
    }
    /**
     * 通过id查询选择题
     *
     * @return 选择题
     */
    @GetMapping("/multiQuestionId")
    public R<SysMultiQuestionEntity> findOnlyQuestion() {
        SysMultiQuestionEntity res = sysMultiQuestionService.findOnlyQuestionId();
        return ApiResultHandler.buildApiResult(200,"查询成功",res);
    }

}
